var staticpage = liwe.module ( "staticpage" );

staticpage._static_page = {};


staticpage.init = function ()
{
	if ( ! staticpage.templates )
	{
		liwe.AJAX.easy ( { action: "staticpage.ajax.get_templates" }, function ( v ) {
			staticpage.templates = v [ 'templates' ];
		} );
	}
};

staticpage.get_page = function ( page, db, cback )
{
	var p = staticpage._static_page.get ( page );

	function _get_page ()
	{
		cback && cback ( staticpage._static_page [ page ] );
	}

	if ( p )
		_get_page ();
	else
	{
		var act = 'staticpage.ajax.get_static_page_by_name';
		if ( ! db ) act = "staticpage.ajax.get_html_page";

		liwe.AJAX.easy ( { action: act, 'page': page }, function ( v ) {
			staticpage._static_page [ page ] = v [ 'page' ];
			_get_page ();
		} );
	}
};

staticpage.plugin = function ( div, params )
{
	var _page = params [ 'name' ];

	staticpage.get_page ( _page, true, function ()
	{
		div.innerHTML = staticpage._static_page [ _page ] [ 'html' ];
	} );
};
